Skip to content

refactor: strip comments and simplify the downgrader in orpc style - #11

Merged
dinwwwh merged 1 commit into
mainfrom
claude/recursing-wescoff-a8f180
Sep 7, 2026
Merged

refactor: strip comments and simplify the downgrader in orpc style#11
dinwwwh merged 1 commit into
mainfrom
claude/recursing-wescoff-a8f180

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Sep 7, 2026

Copy link
Copy Markdown
Member

Brings packages/ in line with the middleapi/orpc convention of letting names explain the code. The downgrader source and tests lose their file headers, internal JSDoc, SAFETY: notes, and inline restatements of spec rules the README already documents; the types package loses its file headers and vocabulary divider comments while keeping the per-field spec JSDoc that powers hover docs. Alongside, the downgrader drops a few layers of indirection. Behaviour is unchanged.

Simplifications

  • convertSpec wrappers are inlined into downgradeSpecV31ToV30 and downgradeSpecV32ToV31, and the exported functions cast their result directly.
  • Path Item $ref inlining merges the referenced item into the referencing one before converting, so the two casts and the spread-versus-assign note are gone; output is identical.
  • The mutualTls set is replaced by an isMutualTls lookup on the existing scheme-type map.
  • Literal-key writes use plain assignment instead of setOwn; required and convertType lose redundant branches.

Kept on purpose

  • convertSchema stays as the untyped internal entry point: the recursion feeds it unknown subtrees, and routing those through the typed export would need casts at every call site or an unknown overload in the public API.
  • @ts-expect-error directives in the type tests, and one-line notes on why two corpus fixtures are excluded.

Testing

  • pnpm lint, pnpm type:check, and pnpm test pass; all 350 tests green with snapshots unchanged.

Code in packages/ now follows the middleapi/orpc convention of letting
names explain the code: file headers, internal JSDoc, SAFETY notes on
casts, and inline restatements of spec rules (already covered by the
README) are gone from the downgrader source and tests, and the types
package loses its file headers and vocabulary divider comments while
keeping the per-field spec JSDoc.

The downgrader is also simplified: the convertSpec wrappers are inlined
into the exported functions, path item inlining merges the referenced
item before converting instead of merging two converted outputs, the
mutualTLS set is replaced by a lookup on the scheme-type map, and
literal-key writes use plain assignment.
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Clean refactor — one doc-preservation observation inline.

Reviewed changes

  • Comment stripping — removed file headers, internal JSDoc, SAFETY: notes, and spec-rule restatements from the downgrader source/tests and the types package, keeping the per-field schema JSDoc that powers hover docs.
  • convertSpec wrappers inlineddowngradeSpecV31ToV30 / downgradeSpecV32ToV31 now cast their result directly instead of routing through a private wrapper.
  • Path Item $ref inlining rewrite — merges target and own before converting instead of converting-then-skipping; verified equivalent, and the own-wins / chain / callback / cycle / mutualTLS-inside-inlined behaviors are all pinned by existing tests (v3.1-to-v3.0.test.ts:158-297).
  • mutualTls set → isMutualTls lookup — reads context.schemeTypes directly; the two are bijectively equivalent since mutualTls was populated for exactly the names whose resolved type is 'mutualTLS'.
  • setOwn → plain assignment, branch dedups — every replaced site writes a literal key (type, $ref, minimum, required, …), never a user-dynamic key, so the __proto__ hardening in setOwn is genuinely unnecessary there; the required / convertType / applyTypes / convertContentKeywords restructurings are control-flow-identical.

I verified equivalence by tracing each restructure (the content: convertContent in convertParameterOrHeader is a pre-existing alias of the removed inline mapRecord(item, convertMediaType)), and confirmed correctness: 350 tests green with snapshots unchanged, output re-validated against the official 3.0/3.1 schemas, plus pnpm type:check and pnpm lint clean.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏

* @see {@link https://spec.openapis.org/oas/v3.1.2.html}
*/

import type {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed header was the only place documenting the cross-version architecture and version delta — nullable is gone (use type arrays), $ref is a plain schema keyword, boolean schemas are valid, and structurally-identical types are re-exported from ./v3.0. The per-field JSDoc survives and even mentions Draft 2020-12, but nothing anywhere now states the relationship/strategy this header captured, which the downgrader's SCHEMA_FIELDS/applyTypes implicitly encode. Consider keeping that one orientation paragraph — as a short header or in a package README — so the info isn't lost from the repo.

@dinwwwh
dinwwwh merged commit e86d61b into main Sep 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant